package com.example.kafka.controller;

import com.example.kafka.service.OffsetCommitBeforeProcessService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 演示先提交位点后处理消息的错误示例
 */
@RestController
@RequestMapping("/api/v1/offset-commit-before-process")
@RequiredArgsConstructor
public class OffsetCommitBeforeProcessController {

    private final OffsetCommitBeforeProcessService service;

    /**
     * 用例1: 订单处理 - 先提交位点后处理订单
     */
    @PostMapping("/order")
    public String processOrder(@RequestBody String orderData) {
        return service.processOrder(orderData);
    }

    /**
     * 用例2: 支付处理 - 先提交位点后处理支付
     */
    @PostMapping("/payment")
    public String processPayment(@RequestBody String paymentData) {
        return service.processPayment(paymentData);
    }

    /**
     * 用例3: 库存更新 - 先提交位点后更新库存
     */
    @PostMapping("/inventory")
    public String updateInventory(@RequestBody String inventoryData) {
        return service.updateInventory(inventoryData);
    }

    /**
     * 用例4: 用户注册 - 先提交位点后处理注册
     */
    @PostMapping("/user-registration")
    public String processUserRegistration(@RequestBody String userData) {
        return service.processUserRegistration(userData);
    }

    /**
     * 用例5: 日志处理 - 先提交位点后处理日志
     */
    @PostMapping("/log")
    public String processLog(@RequestBody String logData) {
        return service.processLog(logData);
    }
}
